﻿using Sai.Core;
using Sai.Core.Introspection;
using Sai.Test.TestDataBuilders;
using Sai.Test.XUnit;
using Xunit;

namespace Sai.Test
{

    public class SourceCodeFacts
    {
        [Fact, InMemoryTest]
        public void TypeName_As_Xml_Include_Full_Name()
        {
            TypeName returnType = TypeNameBuilder.Type()
                .Named("TestClass")
                .InNamespace("MyLib")
                .Build();

            SourceCode code = SourceCodeTypeNameBuilder.Type(returnType).Build();

            string flat = code.ToXml();

            Assert.Contains("<SourceCode>", flat);
            Assert.Contains("<tn>MyLib.TestClass</tn>", flat);
            Assert.Contains("</SourceCode>", flat);
        }

                  
        [Fact, InMemoryTest]
        public void Equals_Returns_True_For_Identical_Source_Code()
        {
            SourceCode thisCode = new SourceCode();
            thisCode.Add(new TypeNameTag("ThisIsMyType"));

            SourceCode thatCode = new SourceCode();
            thatCode.Add(new TypeNameTag("ThisIsMyType"));

            Assert.Equal(thisCode, thatCode);
        }

        [Fact, InMemoryTest]
        public void Equals_Returns_False_For_NonIdentical_Source_Code()
        {
            SourceCode thisCode = new SourceCode();
            thisCode.Add(new TypeNameTag("ThisIsMyType"));

            SourceCode thatCode = new SourceCode();
            thatCode.Add(new TypeNameTag("ThisIsNotMyType"));

            Assert.NotEqual(thisCode, thatCode);
        }

    }
}
